from django.template import Library

register = Library()

@register.simple_tag
def project_size(size):
    # 判断传入的字节是否大于GB
    if size >= 1024 * 1024 * 1024 :
        return "%.2f GB" %(size/(1024*1024*1024))
    elif size >= 1024 * 1024:
        return "%.2f MB" % (size / (1024 * 1024),)
    elif size >= 1024:
        return "%.2f KB" % (size / 1024,)
    else:
        return "%d B" % size
